package createThread.cn.tedu.threaddemo.test6;

public class Test {
    public static void main(String[] args) {
        Object lock1 = new Object();
        Object lock2 = new Object();
        Thread t1 = new Thread(()->{
            synchronized(lock1){
                System.out.println("线程1拿到锁1");
                synchronized (lock2){
                    System.out.println("线程1拿到锁2");
                }
            }
            System.out.println("线程1结束");
        });
        Thread t2 = new Thread(()->{
            synchronized(lock1){
                System.out.println("线程2拿到锁1");
                synchronized (lock2){
                    System.out.println("线程2拿到锁2");
                }
            }
            System.out.println("线程2结束");
        });
        t1.start();
        t2.start();
    }
}
